package queueenum

import (
	"yunj/pkg/yunj/core/enum"
)

// 此处不自定义类型，防止数据库占位符?替换为字符串，在mysql进行匹配时发生类型转换

// 定义常量
const (
	// 已暂停
	STATUS_PAUSED uint8 = 0

	// 运行中
	STATUS_RUNNING uint8 = 11
)

// 实现EnumInerface接口
type Status struct {
	enum.Enum[uint8]
}

// Status.GetInstance().GetDescMap()
func (e *Status) AllConstAttrs() map[uint8]map[string]any {
	return map[uint8]map[string]any{
		STATUS_PAUSED: {
			"desc":  "已暂停",
			"sort":  1,
			"color": "#2F363C",
		},
		STATUS_RUNNING: {
			"desc":  "运行中",
			"sort":  2,
			"color": "#009688",
		},
	}
}

// 存储已经创建的实例
var statusInstanceCache = make(map[uint8]*Status)

// 根据value获取枚举
func StatusByValue(value uint8) *Status {
	if instance, exists := statusInstanceCache[value]; exists {
		return instance
	}
	e := &Status{}
	enum.SetEnumInstance(&e.Enum, e, value)
	statusInstanceCache[value] = e
	return e
}

var StatusEnum *Status = func() *Status {
	e := &Status{}
	enum.SetEnumInstance(&e.Enum, e)
	return e
}()
